﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace Qero.ChartPoint
{
    [System.Runtime.InteropServices.ComVisible(true)]
    [System.Runtime.InteropServices.Guid("D641774F-DAC9-4fa3-9D63-1EB286B506CA")]
    public sealed partial class AppRootControl : UserControl
    {
        private string folderPath;
        private Outlook.Application currApp;

        public AppRootControl()
        {
            InitializeComponent();
        }

#if !INSTALL
        
        /// <summary> Registers the type as safe for scripting
        /// </summary>
        [System.Runtime.InteropServices.ComRegisterFunction()]
        public static void RegisterServer(Type type)
        {
            RegisterHomepage.RegisterSafeForScripting(type);
        }

        /// <summary> Unregisters the type
        /// </summary>
        [System.Runtime.InteropServices.ComUnregisterFunction()]
        public static void UnregisterServer(Type type)
        {
            RegisterHomepage.UnregisterSafeForScripting(type);
        }

#endif

        public void Initialize(Outlook.Application app, string folderName)
        {
            if (app == null) { return; }

            currApp = app;
            folderPath = folderName;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Stopwatch sWatch = new System.Diagnostics.Stopwatch();
            sWatch.Start();

            //CPTable dataTbl = CPTable.Chart;

            //DataQuarkLine chartData = new DataQuarkLine();
            //chartData.dataTable = dataTbl;

            //chartData.LineSet.Add(new DataQuark(dataTbl.ToString() + DataClass.FLD_Uid, QDType.GUID, Guid.NewGuid()));
            //chartData.LineSet.Add(new DataQuark(dataTbl.ToString() + DataClass.FLD_Sub, QDType.TEXT, "Order"));
            //chartData.LineSet.Add(new DataQuark(dataTbl.ToString() + DataClass.FLD_Name, QDType.TEXT, "Docs"));
            //chartData.LineSet.Add(new DataQuark(dataTbl.ToString() + DataClass.FLD_Files, QDType.BOOL, true));
            //chartData.LineSet.Add(new DataQuark(dataTbl.ToString() + DataClass.FLD_Files, QDType.BOOL, Charter.GetYesno(updChart.newItem.filesApp)));

            //DataClass.InsertTable(chartData);
            //DataQuarkLine[] charterSet = DataClass.SelectCharter();

            sWatch.Stop();

            MessageBox.Show("AddIn Startup - " + System.Reflection.Assembly.GetExecutingAssembly().FullName + Environment.NewLine + System.Reflection.Assembly.GetExecutingAssembly().Location);
            //SQLiteClass mydb = new SQLiteClass();
            //string sSql = @"CREATE TABLE [birthday]([id] INTEGER PRIMARY KEY AUTOINCREMENT";
            //sSql += ",[FIO] TEXT NOT NULL,[bdate] datetime NOT NULL,[gretinyear] INTEGER DEFAULT 0);";
            ////Пытаемся создать базу данных и таблицу одновременно, так как создание
            ////базы данных есть всего лишь процесс создания пустого файла при организации
            ////connection, или указание на файл, если БД (файл) существует
            ////Третий параметр функции говорит, что БД создается вновь
            //int outInt = mydb.iExecuteNonQuery(BaseUnit.DBDefaultPath, sSql, 0);

            //if (outInt < 0) MessageBox.Show("Is errored request!");
        }
    }
}
